﻿@{
	ViewBag.Title = "OMSBL";
}

@functions{
    public class Schedule
    {
        public string EventName { get; set; }
        public string Location { get; set; }
        public string StartTime { get; set; }
        public DateTime StartDate { get; set; }
    }
    private static string CalendarService = "https://www.googleapis.com/calendar/v3/calendars/{0}/events?orderBy=startTime&singleEvents=true&key={1}&timeMin={3}&timeMax={2}";
    private string calid = System.Configuration.ConfigurationManager.AppSettings["CalendarId"].ToString();
    private string apikey = System.Configuration.ConfigurationManager.AppSettings["APIKey"].ToString();
    
    public static List<Schedule> GetEvents(string calendarid, string apikey)
    {
        string dwml = string.Empty;
        DateTime current = DateTime.Now.AddHours(-8);
        DateTime timeMax = DateTime.Now.AddDays(7);
        System.Net.WebClient webClient = new System.Net.WebClient();
        
        string serviceURL = string.Format(CalendarService, calendarid, apikey,
            HttpUtility.UrlEncode(timeMax.ToString("yyyy-MM-ddTHH:mm:sszzzz")),
            HttpUtility.UrlEncode(current.ToString("yyyy-MM-ddTHH:mm:sszzzz")));
        
        dwml = webClient.DownloadString(serviceURL);
        return JSONToSchedule(dwml);
    }
    private static List<Schedule> JSONToSchedule(string schedtoparse)
    {
        var temp = Json.Decode(schedtoparse);
        List<Schedule> returnsched = new List<Schedule>();
        foreach (var item in temp.items)
        {
            Schedule sched = new Schedule();
            sched.EventName = item.summary;
            sched.Location = item.location;
            sched.StartDate = Convert.ToDateTime(item.start.dateTime);
            returnsched.Add(sched);
        }
        return returnsched;
    }
}
	<div id="header" class="header">
				
	</div>

	<div class="main">
	
		<div class="left">

			<div class="content">
				<h1>Congratulations to the Omaha 50+ team</h1>
				<div class="descr">Nov 11, 2012</div>

				<p>Congratulations to the 50+ Omaha team for their third place finish in this years national tournament in Phoenix.</p>

				<img alt="World Series 50+" src="../../Images/50plusnational.jpg" width="350px" height="200px" />
				<img width="150px" height="75px" alt="Men's Senior World Series" src="../../Images/WorldSeriesFeatured.png" />
				<br />
				<br />
				<div class="stripes"><span></span></div>

				<h1>Congratulations to the Omaha Yankess</h1>
				<div class="descr">Nov 13, 2012</div>

				<p>Congratulations to the Omaha Yankees for winning the 2012 League Championship.</p>

				<img alt="Omaha Yankees" src="../../Images/OmahaYankees.jpg" width="150px" height="75px" />
			</div>

		</div>

		<div class="right">

			<div class="subnav">

				<h1>Announcements</h1>
				<p>We are currently redesigning the OMSBL site.</p>

				<h1>Scores</h1>
				<ul>

				</ul>

				<h1>Upcoming Schedule</h1>
				@*<p>Days until Spring Training:</p><div id="defaultCountdown"></div>*@
                <ul>              
                @foreach (var kvp in @GetEvents(calid, apikey))
                {
                    //string zone = ;
                    //TimeZoneInfo ti = TimeZoneInfo.FindSystemTimeZoneById(zone);

                    //string time = kvp.StartDate.ToLocalTime().ToShortTimeString();
                    <li style="border-style: solid">@String.Format("{0:dddd MMMM d, yyyy}",kvp.StartDate) <br />  @kvp.EventName <br /> @kvp.Location  at @String.Format("{0:t}", TimeZoneInfo.ConvertTimeBySystemTimeZoneId(kvp.StartDate, "Central Standard Time").ToShortTimeString())</li>
                }
                </ul> 
			</div>
		</div>

		<div class="clearer"><span></span></div>

	</div>

			<div id="footer">
				
			</div>

@*            <script>
                function myFunction() {
                    var d = new Date();
                    var x = document.getElementById("demo");
                    x.innerHTML = d.toTimeString();
                }
</script>*@


